//
//  TBRRecevePlaneDurationPickerC.m
//  TBRentClient
//
//  Created by tonbright on 2018/5/23.
//  Copyright © 2018年 tonbright. All rights reserved.
//

#import "TBRRecevePlaneDurationPickerC.h"
@interface TBRRecevePlaneDurationPickerC ()<UIPickerViewDataSource,UIPickerViewDelegate>
@property (nonatomic,strong)NSMutableArray *dateArray;

@end

@implementation TBRRecevePlaneDurationPickerC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.pickerView.dataSource = self;
    self.pickerView.delegate = self;
    self.dateArray = [NSMutableArray array];
    for (NSInteger i = 1; i <= 9; i++) {
        NSString *timeDuraion = [NSString stringWithFormat:@"%ld",i*10];
        [self.dateArray addObject:timeDuraion];
    }
    [self.pickerView selectRow:0 inComponent:0 animated:NO];
    [self.pickerView selectRow:0 inComponent:1 animated:NO];
    [self.pickerView selectRow:0 inComponent:2 animated:NO];
}

- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView {
    return 3;
}

- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component {
    if (component == 0 || component == 2) {
        return 1;
    }
    return self.dateArray.count;
}

- (CGFloat)pickerView:(UIPickerView *)pickerView rowHeightForComponent:(NSInteger)component {
    return 40;
}

- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {
    if (component == 0) {
        return @"到达后";
    }else if (component == 2) {
        return @"分钟";
    }
    NSString *dateStr = self.dateArray[row];
    return dateStr;
}

- (CGFloat)pickerView:(UIPickerView *)pickerView widthForComponent:(NSInteger)component {
    if (component == 0) {
        return Width / 2.4;
    }else if (component == 2){
        return Width / 2.4;
    }
    return Width - Width / 1.2;
}


- (IBAction)cancleBtnClick:(UIButton *)sender {
    
    if (sender.tag == 10) {
        
        if (self.pickerViewCancleBtnBlock) {
            self.pickerViewCancleBtnBlock();
        }
    }else if (sender.tag == 20) {
        NSInteger dateIndex = [self.pickerView selectedRowInComponent:1];
        if (self.pickerViewSureBtnBlock) {
            self.pickerViewSureBtnBlock(self.dateArray[dateIndex]);
        }
        //记录选中的接机时间----------
    }
}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    if (self.pickerViewCancleBtnBlock) {
        self.pickerViewCancleBtnBlock();
    }
}
@end
